/// <reference path="../types.d.ts" />
export const checkOptions = (value: any): ExposureOptions => {
  const options = {} as ExposureOptions
  if (Object.prototype.toString.call(value) === '[object Function]') {
    options.callback = value
  } else if (Object.prototype.toString.call(value) === '[object Object]') {
    const { callback, exposureThreshold } = value
    options.callback = callback
    options.exposureThreshold = exposureThreshold
  }
  return options
}

export const deepEqual = (a: any, b: any): boolean => {
  if (a === b) return true;
  if (typeof a !== 'object' || typeof b !== 'object') return false;
  const keysA = Object.keys(a);
  const keysB = Object.keys(b);
  if (keysA.length !== keysB.length) return false;
  return keysA.every(key =>
    Object.prototype.hasOwnProperty.call(b, key) &&
    deepEqual(a[key], b[key])
  );
}